package com.sky.tests;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import java.util.concurrent.TimeUnit;

@SpringBootTest
public class RedisTest01 {
    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void Stringtest(){
        //1.获取对象
        ValueOperations valueOperations = redisTemplate.opsForValue();
        //2.set key value
        valueOperations.set("name", "zhangsan");
        //3.get key
        valueOperations.get("name");
        //4.setex key seconds value
        valueOperations.set("name","zhangsan",100, TimeUnit.SECONDS);
        //5.setnx key value
        valueOperations.setIfAbsent("name2","zhangsan");
        redisTemplate.opsForHash();//hash对象
        redisTemplate.opsForList();//list操作对象
        redisTemplate.opsForSet();//set操作对象
        redisTemplate.opsForZSet();//zset操作对象
        //2.执行对应的操作

    }
    @Test
    public void  test02(){
        //1.获取对象
        HashOperations hashOperations = redisTemplate.opsForHash();
        //hset key field value
        hashOperations.put("key","field","value");
        ////hget key field
        //hashOperations.get("key","field");
        ////hdel key filed
        //hashOperations.delete("key","field");
        ////hkeys key 获取所有field
        //hashOperations.keys("key");
        ////hvals key 获取所有value
        //hashOperations.values("key");

    }



}
